package gitdemo1.git3.demo;

import java.util.Arrays;
import java.util.Scanner;

public class Son extends Father{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int arr[]=new int[n+1];
        arr[0]=-1;
        for (int i = 1; i <=n ; i++) {
            arr[i]=process(i);
        }

        Arrays.sort(arr);
        System.out.println(arr[m]);

    }
    public static int process(int a){
        int sum=0;
        while (a > 0) {
            sum+=a%10;
            a/=10;
        }
        return sum;
    }
}
